import QtQuick 2.0
import QtQuick.Window 2.12
import "../components"

Window {

    minimumWidth:  430*dp
    minimumHeight: 510*dp
    maximumWidth:  430*dp
    maximumHeight: 510*dp

    property var programList: []
    flags: Qt.Window | Qt.WindowTitleHint |Qt.WindowSystemMenuHint | Qt.WindowCloseButtonHint

    onVisibleChanged: {
        if(visible){
            edit_program.model = gComboModel_program
            edit_kit.model = gComboModel_kit
            edit_system.model = gComboModel_system
            edit_consume.model = gComboModel_consume

            edit_name.setText(Qt.formatDateTime(new Date, "yyyyMMddhhmmss"))
            edit_program.changeCurrentIndex(gDefaultIdx_program)
            edit_code.setText("001")
            edit_kit.changeCurrentIndex(0)
            edit_system.changeCurrentIndex(0)
            edit_consume.changeCurrentIndex(0)
        }

    }

    id: root

    title: "新建实验"

    signal accept()
    signal reject()

    modality: Qt.WindowModal

    Item{           // 居中显示
        anchors.centerIn: parent
        height: 340*dp
        width: 380*dp
        Column{
            anchors.centerIn: parent
            spacing: 16*dp
            width: 340*dp
            height: 380*dp
            LineEditor{
                id: edit_name
                title: "实验名称"
                required: true
                editWidth: 260*dp
                inputMaxLength: 20
                lengthVisible: true
            }
            CustomComboBox{
                id: edit_program
                model: ["扩增程序1", "扩增程序2", "扩增程序3"]

                title: "扩增程序"
                editWidth: 260*dp
            }
            LineEditor{
                id: edit_code
                title: "编码"
                editWidth: 260*dp
                inputMaxLength: 20
            }
            CustomComboBox{
                id: edit_kit
                model: ["试剂盒1", "试剂盒2"]
                title: "试剂盒"
                editWidth: 260*dp
            }
            CustomComboBox{
                id: edit_system
                title: "体系(μl)"
                model: [10]
                editWidth: 260*dp
            }
            CustomComboBox{
                id: edit_consume
                model: ["耗材1", "耗材2"]
                title: "耗材"
                editWidth: 260*dp
            }

        }
    }
    Item{
        height: 40*dp
        width: root.width
        y: root.height - 90*dp

        PushButton{
            x: root.width / 2 - 130*dp
            title: "取消"
            defaultMode2: true
            onReleased: {
                root.close()
                reject()
            }
        }PushButton{
            x: root.width / 2 + 10*dp
            title: "确定"
            defaultMode1: true
            onReleased: {
                if(edit_program.getText()==="" || edit_name.getText()===""){
                    mainwindow.showToast("请完整填写实验信息", 1)
                }else{
                    var amplName = edit_program.getText()
                    gExperimentInfo["AmplGuid"] = ""
                    var programList = CAmplProgram.getProgramInfo(0)
                    for(let i = 0; i < programList.length; i ++){
                        if(amplName === programList[i]["ProgramName"]){
                            gExperimentInfo["AmplGuid"] = programList[i]["Id"]
                        }
                    }
                    gExperimentInfo["ExperimentName"] = edit_name.getText()
                    gExperimentInfo["Code"] =           edit_code.getText()
                    gExperimentInfo["System"] =         edit_system.getText()
                    gExperimentInfo["ConsumableType"] = edit_consume.getText()
                    gExperimentInfo["TestKit"] =        edit_kit.getText()

                    root.close()
                    accept()
                }

            }
        }
    }
}
